<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Doc</title>
<style type="text/css">
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*
<span class='line'>  2</span>  *  574 bytes minified and gzipped
<span class='line'>  3</span>  * 
<span class='line'>  4</span>  *  Its comprised of the following extensions to Function
<span class='line'>  5</span>  * 
<span class='line'>  6</span>  *     #inherit
<span class='line'>  7</span>  *     #implement
<span class='line'>  8</span>  *     #implementStatic
<span class='line'>  9</span>  *     #is
<span class='line'> 10</span>  *     #bind
<span class='line'> 11</span>  *     #getName
<span class='line'> 12</span>  *     
<span class='line'> 13</span>  * @author David Foley | david@ondevice.ie
<span class='line'> 14</span>  */</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="COMM">/**
<span class='line'> 16</span>  * @fileOverview The core bundle of method extensions to Function.prototype
<span class='line'> 17</span>  * @author &lt;a href="mailto:david@ondevice.ie">David Foley&lt;/a>
<span class='line'> 18</span>  * @version 0.3
<span class='line'> 19</span>  */</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="WHIT">        </span><span class="COMM">/**
<span class='line'> 23</span>          * @private
<span class='line'> 24</span>          * A static reference to Function.prototype
<span class='line'> 25</span>          * @type {Object}
<span class='line'> 26</span>          */</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">F</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Function.prototype</span><span class="WHIT">
<span class='line'> 28</span> 
<span class='line'> 29</span> </span><span class="WHIT">        </span><span class="COMM">/**
<span class='line'> 30</span>          * @private
<span class='line'> 31</span>          * A static reference to the word anonymous
<span class='line'> 32</span>          * @type {String}
<span class='line'> 33</span>          */</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">    </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">A</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'anonymous'</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">        </span><span class="COMM">/**
<span class='line'> 36</span>          * @private
<span class='line'> 37</span>          * A static reference to the Array.prototype.slice method
<span class='line'> 38</span>          * @type {Function}
<span class='line'> 39</span>          */</span><span class="WHIT">
<span class='line'> 40</span> </span><span class="WHIT">    </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">slice</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Array.prototype.slice</span><span class="WHIT">
<span class='line'> 41</span> 
<span class='line'> 42</span> </span><span class="WHIT">        </span><span class="COMM">/**
<span class='line'> 43</span>          * @private
<span class='line'> 44</span>          * Flag used to prevent or allow member overriding
<span class='line'> 45</span>          * @type {Boolean}
<span class='line'> 46</span>          */</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">    </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">preventOverride</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="WHIT">
<span class='line'> 48</span> 
<span class='line'> 49</span> </span><span class="WHIT">        </span><span class="COMM">/**
<span class='line'> 50</span>          * @private
<span class='line'> 51</span>          * Internal method used by traits.implementStatic to implement traits.
<span class='line'> 52</span>          *
<span class='line'> 53</span>          * @param {String} accessor        The name of the trait
<span class='line'> 54</span>          * @param {Object} value           The value of the trait
<span class='line'> 55</span>          * @param {Object} subject         The object on which the trait will be put
<span class='line'> 56</span>          * @param {Boolean} canOverwrite   Whether to allow overwriting or not
<span class='line'> 57</span>          * @return {void}
<span class='line'> 58</span>          */</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">    </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">put</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">accessor</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">subject</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">canOverwrite</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">        </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">canOverwrite</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="PUNC">(</span><span class="NAME">accessor</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">subject</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'> 62</span>                 </span><span class="NAME">subject</span><span class="PUNC">[</span><span class="NAME">accessor</span><span class="PUNC">]</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 64</span> 
<span class='line'> 65</span> </span><span class="WHIT">        </span><span class="COMM">/*
<span class='line'> 66</span>          * The traits that will be implemented on Function.prototype.
<span class='line'> 67</span>          */</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">    </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">traits</span><span class="PUNC">=</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">        </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">            </span><span class="COMM">/**
<span class='line'> 71</span>              * Extend one constructors prototype by anothers. 
<span class='line'> 72</span>              * 
<span class='line'> 73</span>              * @example Child.inherit(Parent);
<span class='line'> 74</span>              * 
<span class='line'> 75</span>              * @example
<span class='line'> 76</span>              * &lt;code>&lt;pre>
<span class='line'> 77</span>              * // a mock superclass
<span class='line'> 78</span>              * Parent.implement
<span class='line'> 79</span>              * (
<span class='line'> 80</span>              *     function setValue (value)
<span class='line'> 81</span>              *     {
<span class='line'> 82</span>              *         this.value= value;
<span class='line'> 83</span>              *     }
<span class='line'> 84</span>              * );
<span class='line'> 85</span>              * 
<span class='line'> 86</span>              * function Parent () {;};
<span class='line'> 87</span>              * 
<span class='line'> 88</span>              * // a mock subclass
<span class='line'> 89</span>              * Child.inherit(Parent).implement
<span class='line'> 90</span>              * (
<span class='line'> 91</span>              *     // override the parent method
<span class='line'> 92</span>              *     function setValue (value)
<span class='line'> 93</span>              *     {
<span class='line'> 94</span>              *         // introduce a guard clause
<span class='line'> 95</span>              *         if (false === Number.is(value))
<span class='line'> 96</span>              *             throw new TypeError ('Number expected');
<span class='line'> 97</span>              *             
<span class='line'> 98</span>              *         // call the superclass method like this
<span class='line'> 99</span>              *         this.parent.setValue.call(this, value);
<span class='line'>100</span>              *     }
<span class='line'>101</span>              * 
<span class='line'>102</span>              * );
<span class='line'>103</span>              * 
<span class='line'>104</span>              * function Child () 
<span class='line'>105</span>              * {
<span class='line'>106</span>              *     // apply the superclass constructor logic to this instance
<span class='line'>107</span>              *     Parent.call(this, 'defaultChildValue');
<span class='line'>108</span>              * }
<span class='line'>109</span>              * &lt;/pre>&lt;/code>
<span class='line'>110</span>              * 
<span class='line'>111</span>              * @name inherit
<span class='line'>112</span>              * @methodOf Function
<span class='line'>113</span>              * @param {Function} Parent    The constructor to inherit from.
<span class='line'>114</span>              * @return {Function}          The extended prototypes constructor.
<span class='line'>115</span>              * @throws {TypeError}         If Parent is an invalid constructor.
<span class='line'>116</span>              */</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">            </span><span class="NAME">inherit</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Parent</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">            </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">                </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">'function'</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">Parent</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NAME">Parent</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT">                    </span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">TypeError</span><span class="PUNC">(</span><span class="STRN">'Inheritance error.'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>121</span> 
<span class='line'>122</span> </span><span class="WHIT">                </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">Intermediary</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">;</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">                </span><span class="NAME">Intermediary.prototype</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Parent.prototype</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>124</span> 
<span class='line'>125</span> </span><span class="WHIT">                </span><span class="NAME">this.prototype</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Intermediary</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT">                </span><span class="NAME">this.prototype.constructor</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">                </span><span class="NAME">this.prototype.parent</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Parent.prototype</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">            
<span class='line'>131</span>             </span><span class="COMM">/**
<span class='line'>132</span>              * Implement any number of traits on a constructors prototype. Traits
<span class='line'>133</span>              * are added subject to the same rules enforced by #implementStatic.
<span class='line'>134</span>              * 
<span class='line'>135</span>              * @example
<span class='line'>136</span>              * &lt;code>&lt;pre>
<span class='line'>137</span>              * // 1. Using named functions
<span class='line'>138</span>              * CustomObject.implement
<span class='line'>139</span>              * (
<span class='line'>140</span>              *     function method () 
<span class='line'>141</span>              *     {
<span class='line'>142</span>              *         // implementation
<span class='line'>143</span>              *     }
<span class='line'>144</span>              * );
<span class='line'>145</span>              * 
<span class='line'>146</span>              * function CustomObject ()
<span class='line'>147</span>              * {
<span class='line'>148</span>              *     this.method();
<span class='line'>149</span>              * };
<span class='line'>150</span>              * &lt;/pre>&lt;/code>
<span class='line'>151</span>              * 
<span class='line'>152</span>              * @description description continued here
<span class='line'>153</span>              * @example
<span class='line'>154</span>              * &lt;code>
<span class='line'>155</span>              * &lt;pre>
<span class='line'>156</span>              * //2. Using an object literal
<span class='line'>157</span>              * CustomObject.implement
<span class='line'>158</span>              * (
<span class='line'>159</span>              *     {
<span class='line'>160</span>              *         property: null
<span class='line'>161</span>              *         
<span class='line'>162</span>              *     ,   method: function () 
<span class='line'>163</span>              *         {
<span class='line'>164</span>              *             // implementation
<span class='line'>165</span>              *         }
<span class='line'>166</span>              *     }
<span class='line'>167</span>              * );
<span class='line'>168</span>              * 
<span class='line'>169</span>              * &lt;/pre>
<span class='line'>170</span>              * &lt;/code>
<span class='line'>171</span>              * The method also lends itself to trait borrowing quite well.
<span class='line'>172</span>              * 
<span class='line'>173</span>              * @example
<span class='line'>174</span>              * &lt;code>&lt;pre>
<span class='line'>175</span>              * AnotherCustomObject.implement(CustomObject.prototype);
<span class='line'>176</span>              * function AnotherCustomObject ()
<span class='line'>177</span>              * {
<span class='line'>178</span>              *     this.method();
<span class='line'>179</span>              * };
<span class='line'>180</span>              * &lt;/pre>&lt;/code>
<span class='line'>181</span>              * 
<span class='line'>182</span>              * &lt;p>And defining dynamic class instances&lt;/p>
<span class='line'>183</span>              * @example
<span class='line'>184</span>              * &lt;code>&lt;pre>
<span class='line'>185</span>              * var mixin= new function (value)
<span class='line'>186</span>              * {
<span class='line'>187</span>              *     var hiddenValue= value;
<span class='line'>188</span>              *     this.constructor.implement
<span class='line'>189</span>              *     (
<span class='line'>190</span>              *         function getHiddenValue () 
<span class='line'>191</span>              *         {
<span class='line'>192</span>              *             return hiddenValue
<span class='line'>193</span>              *         }
<span class='line'>194</span>              *     );
<span class='line'>195</span>              * }('someValue');
<span class='line'>196</span>              * &lt;/pre>&lt;/code>
<span class='line'>197</span>              * 
<span class='line'>198</span>              * @name implement
<span class='line'>199</span>              * @methodOf Function
<span class='line'>200</span>              * @param {Object...} arguments
<span class='line'>201</span>              * @return {Function} The constructor 
<span class='line'>202</span>              * @see #implementStatic
<span class='line'>203</span>              */</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">implement</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>205</span> </span><span class="WHIT">            </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>206</span> </span><span class="WHIT">                </span><span class="COMM">// there is the potential for this constructors prototypes</span><span class="WHIT">
<span class='line'>207</span> </span><span class="WHIT">                </span><span class="COMM">// constructor being overwritten during the course of implementing</span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT">                </span><span class="COMM">// traits, so we make sure to apply the correct value here at all</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT">                </span><span class="COMM">// times, simplifying the trait implementation process</span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT">               </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.implementStatic.apply</span><span class="PUNC">(</span><span class="NAME">this.prototype</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">constructor</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT">            
<span class='line'>213</span>             </span><span class="COMM">/**
<span class='line'>214</span>              * Implement any number of traits on a constructor.
<span class='line'>215</span>              * @name implementStatic
<span class='line'>216</span>              * @methodOf Function
<span class='line'>217</span>              * @param {Object...} arguments
<span class='line'>218</span>              * @return {Function}
<span class='line'>219</span>              * @see #implement
<span class='line'>220</span>              */</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">implementStatic</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>222</span> </span><span class="WHIT">            </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>223</span> </span><span class="WHIT">                </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">trait</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT">
<span class='line'>224</span> </span><span class="WHIT">                </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">canOverwrite</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">F.implement.preventOverride</span><span class="WHIT">
<span class='line'>225</span> </span><span class="WHIT">                </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">accessor</span><span class="WHIT">
<span class='line'>226</span> </span><span class="WHIT">                </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">n</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments.length</span><span class="WHIT">
<span class='line'>227</span> </span><span class="WHIT">                </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">i</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT">                </span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">                
<span class='line'>230</span>                 </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">                </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">                    </span><span class="NAME">trait</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>233</span> </span><span class="WHIT">                    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">trait</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>234</span>                     </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>235</span> </span><span class="WHIT">                        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">'function'</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">trait</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>236</span>                         </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">                            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">A</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">accessor</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">trait.getName</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>238</span> </span><span class="WHIT">                                </span><span class="NAME">put</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">accessor</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">trait</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">canOverwrite</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">                        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">                        </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">accessor</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">trait</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">                        </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">                            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">trait.hasOwnProperty</span><span class="PUNC">(</span><span class="NAME">accessor</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">                                </span><span class="NAME">put</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">accessor</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">trait</span><span class="PUNC">[</span><span class="NAME">accessor</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">canOverwrite</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">                        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>245</span> </span><span class="WHIT">                    </span><span class="PUNC">}</span><span class="WHIT"> 
<span class='line'>246</span>                 </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>247</span> </span><span class="WHIT">                
<span class='line'>248</span>                 </span><span class="COMM">// reset override protection defaults</span><span class="WHIT">
<span class='line'>249</span> </span><span class="WHIT">                </span><span class="NAME">F.implement.preventOverride</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">preventOverride</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>250</span> 
<span class='line'>251</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>252</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>253</span> </span><span class="WHIT">            
<span class='line'>254</span>             </span><span class="COMM">/**
<span class='line'>255</span>              * Determine if a value is an instance of a type, eliding the 
<span class='line'>256</span>              * distinction between primitives and their object counterparts.
<span class='line'>257</span>              * 
<span class='line'>258</span>              * The method will always return false for values of null or
<span class='line'>259</span>              * undefined.
<span class='line'>260</span>              * 
<span class='line'>261</span>              * @name is
<span class='line'>262</span>              * @methodOf Function
<span class='line'>263</span>              * @param {Object} value
<span class='line'>264</span>              * @return {Boolean}
<span class='line'>265</span>              */</span><span class="WHIT">
<span class='line'>266</span> </span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">is</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>267</span> </span><span class="WHIT">            </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>268</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">Object</span><span class="PUNC">(</span><span class="NAME">value</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">instanceof</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>269</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>270</span> </span><span class="WHIT">            
<span class='line'>271</span>             </span><span class="COMM">/**
<span class='line'>272</span>              * Set a functions execution scope and optionally preset the
<span class='line'>273</span>              * arguments that will be supplied to it on execution.
<span class='line'>274</span>              * 
<span class='line'>275</span>              * @name bind
<span class='line'>276</span>              * @methodOf Function
<span class='line'>277</span>              * @param {Object} executionScope    The functions execution scope
<span class='line'>278</span>              * @param {Object...} presetArgs     The arguments the function will use
<span class='line'>279</span>              * @return {Function}                A curried function
<span class='line'>280</span>              */</span><span class="WHIT">
<span class='line'>281</span> </span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">bind</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">executionScope</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>282</span> </span><span class="WHIT">            </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>283</span> </span><span class="WHIT">                </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">method</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="WHIT">
<span class='line'>284</span> </span><span class="WHIT">                </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">presetArgs</span><span class="WHIT">
<span class='line'>285</span> </span><span class="WHIT">                </span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>286</span> 
<span class='line'>287</span> </span><span class="WHIT">                </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">arguments.length</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>288</span> </span><span class="WHIT">                </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>289</span> </span><span class="WHIT">                     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">method.apply</span><span class="PUNC">(</span><span class="NAME">executionScope</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>290</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>291</span> 
<span class='line'>292</span> </span><span class="WHIT">                </span><span class="NAME">presetArgs</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">slice.call</span><span class="PUNC">(</span><span class="NAME">arguments</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>293</span> </span><span class="WHIT">                </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>294</span> </span><span class="WHIT">                </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>295</span> </span><span class="WHIT">                    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">method.apply</span><span class="PUNC">(</span><span class="NAME">executionScope</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">presetArgs.concat</span><span class="PUNC">(</span><span class="NAME">arguments</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>296</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>297</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>298</span> </span><span class="WHIT">            
<span class='line'>299</span>             </span><span class="COMM">/**
<span class='line'>300</span>              * Determine a functions name. If a function is anonymous, or otherwise
<span class='line'>301</span>              * does not have a name, the return value will be 'anonymous'.
<span class='line'>302</span>              * 
<span class='line'>303</span>              * @name getName
<span class='line'>304</span>              * @methodOf Function
<span class='line'>305</span>              * @return {String} The name of a function.
<span class='line'>306</span>              */</span><span class="WHIT">
<span class='line'>307</span> </span><span class="WHIT">        </span><span class="PUNC">,</span><span class="WHIT">   </span><span class="NAME">getName</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>308</span>             </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>309</span> </span><span class="WHIT">                </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">'name'</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">F</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>310</span>                 </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT">                    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.name</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">A</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>313</span> </span><span class="WHIT">                
<span class='line'>314</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>315</span>                 </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>316</span> </span><span class="WHIT">                    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">name</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.name</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>317</span> </span><span class="WHIT">                    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">name</span><span class="PUNC">)</span><span class="WHIT">  </span><span class="COMM">// if the functions name has been cached</span><span class="WHIT">
<span class='line'>318</span> </span><span class="WHIT">                        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">name</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// return it</span><span class="WHIT">
<span class='line'>319</span> </span><span class="WHIT">                    
<span class='line'>320</span>                     </span><span class="COMM">// else decompile and parse the function to get its name    </span><span class="WHIT">
<span class='line'>321</span> </span><span class="WHIT">                    </span><span class="NAME">name</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">match</span><span class="PUNC">(</span><span class="REGX">/^function\s([\w|$]+)/</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>322</span> </span><span class="WHIT">                    </span><span class="COMM">// then cache it before returning</span><span class="WHIT">
<span class='line'>323</span> </span><span class="WHIT">            	    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.name</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">name</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">name</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">A</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>324</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>325</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>326</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>327</span> </span><span class="WHIT">    </span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>328</span> </span><span class="WHIT">    
<span class='line'>329</span>     </span><span class="COMM">// A metaprogramming approach to set up the object model in three steps:</span><span class="WHIT">
<span class='line'>330</span> 
<span class='line'>331</span> </span><span class="WHIT">    </span><span class="COMM">// 1. enable override protection, so as not to override any existing methods</span><span class="WHIT">
<span class='line'>332</span> </span><span class="WHIT">    </span><span class="NAME">traits.implement.preventOverride</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>333</span> 
<span class='line'>334</span> </span><span class="WHIT">    </span><span class="COMM">// 2. copy over the implement method to Function.prototype</span><span class="WHIT">
<span class='line'>335</span> </span><span class="WHIT">    </span><span class="NAME">F.implement</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">traits.implement</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>336</span> 
<span class='line'>337</span> </span><span class="WHIT">    </span><span class="COMM">// 3. call implementStatic in the execution context of Function.prototype</span><span class="WHIT">
<span class='line'>338</span> </span><span class="WHIT">    </span><span class="NAME">traits.implementStatic.call</span><span class="PUNC">(</span><span class="NAME">F</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">traits</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>339</span> </span><span class="PUNC">}</span><span class="PUNC">;</span></pre></body></html>